package com.lqzs.businessmanager.dao

import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.lqzs.businessmanager.BusinessManagerApplication
import com.lqzs.businessmanager.bean.AccessInfo
import com.lqzs.businessmanager.bean.MerChantInfo
import com.lqzs.businessmanager.bean.ReplyInfo

@Database(entities = [AccessInfo::class,ReplyInfo::class, MerChantInfo::class], version = 1)
abstract class AccessDataBase : RoomDatabase() {
    companion object {
        private const val DATA_NAME = "access_db"

        @Volatile
        private var INSTANCE: AccessDataBase? = null

        /**
         * 双重校验锁单例,返回数据库实例
         */
        fun getDataBase(): AccessDataBase = INSTANCE ?: synchronized(this) {
            val instance = INSTANCE ?: Room
                .databaseBuilder(BusinessManagerApplication.getContext(), AccessDataBase::class.java, DATA_NAME)
                .build().also {
                    INSTANCE = it
                }
            instance
        }
    }

    /**
     * 返回 SimpleStudentDao Dao对象
     */
    abstract fun accessDao(): AccessDao
    abstract fun replayDao(): ReplyDao

//    abstract fun eleDao() :EleDao
    abstract fun merChantDao() :MerChantDao
}


